import React from 'react';
import styled from 'styled-components';
import Label from 'components/Basic/Label';
import Description from 'components/Basic/Description';
import HighLighter from 'components/Basic/HighLighter';
import Parameter from 'components/Basic/Parameter';
import { ParameterSection } from 'components/Basic/Section';

const ReadWrapper = styled.div`
  margin-bottom: 50px;
`;

function Read() {
  const formula = `  const cEthAddress = Venus.util.getAddress(Venus.vBNB);

  (async function() {
  
    const srpb = await Venus.eth.read(
      cEthAddress,
      'function supplyRatePerBlock() returns (uint256)',
      // [], // [optional] parameters
      // {}  // [optional] call options, provider, network, plus Ethers.js "overrides"
    );
  
    console.log('vBNB market supply rate per block:', srpb.toString());
  
  })().catch(console.error);`;

  return (
    <ReadWrapper id="venusJS-read">
      <Label title marginBottom>
        Read
      </Label>
      <Description>
        This is a generic method for invoking JSON RPC's eth_call with
        Ethers.js. Use this method to execute a smart contract's constant or
        non-constant member without using gas. This is a read-only method
        intended to read a value or test a transaction for valid parameters. It
        does not create a transaction on the block chain.
      </Description>
      <ParameterSection>
        <Parameter name="address">
          {` (string) The BSC address the transaction is directed to.`}
        </Parameter>
        <Parameter name="method">
          {` (string) The smart contract member in which to invoke.`}
        </Parameter>
        <Parameter name="[parameters]">
          {` (any[]) Parameters of the method to invoke.`}
        </Parameter>
        <Parameter name="[options]">
          {` (CallOptions) Options to set for eth_call, optional ABI (as JSON object), and Ethers.js method overrides. The ABI can be a string of the single intended method, an array of many methods, or a JSON object of the ABI generated by a Solidity compiler.`}
        </Parameter>
        <Parameter name="RETURN">
          {` (Promise<any>) Return value of the invoked smart contract member or an error object if the call failed.`}
        </Parameter>
      </ParameterSection>
      <HighLighter>{formula}</HighLighter>
    </ReadWrapper>
  );
}

export default Read;
